#! /bin/bash

create_dir(){
    #创建本地持久化目录
    mkdir -p service/{prometheus,grafana}/{config,data}
    mkdir -p service/prometheus/config/rules
    mkdir -p service/prometheus/data/prometheus
    # 授权，或者执行提示 Permission denied
    sudo chmod -R 777 ./service
}

# 启动函数
main(){
    docker-compose  ps | grep prometheus > /dev/null
    if [ $? != 0 ]
    then
        create_dir
        docker-compose up -d
        clear
        docker-compose ps
    else
        echo "Confirm to stop the current service!  yes | no"
        read -p "> "  selet
        case $selet in
        y | yes)
            docker-compose down
            ;;
        n | no)
            exit 0
            ;;
        *)
            echo "请输入 yes | no "
            ;;
        esac
    fi
}

main